package com._520it.wms.web.controller;

import com._520it.wms.domain.OrderBill;
import com._520it.wms.query.QueryObject;
import com._520it.wms.service.IOrderBillService;
import com._520it.wms.service.ISupplierService;
import com._520it.wms.util.JSONResult;
import com._520it.wms.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by HASEE on 2017/11/14.
 */
@Controller
@RequestMapping("/orderBill")
public class OrderBillContorller {
    //采购订单信息
    @Autowired
    private IOrderBillService orderBillService;
    //供应商信息
    @Autowired
    private ISupplierService supplierService;

    @RequestMapping("/list")
    @RequiredPermission("采购订单列表")
    public String list(Model model, QueryObject qo) {
        //int a = 1/0; 异常解析器
        model.addAttribute("pageResult", orderBillService.query(qo));
        return "/orderBill/list";
    }

    @RequestMapping("/input")
    @RequiredPermission("采购订单编辑")
    public String input(Long id, Model model) {
        model.addAttribute("suppliers", supplierService.listAll());
        if (id != null) {
            OrderBill orderBill = orderBillService.get(id);
            model.addAttribute("orderBill", orderBill);
        }
        return "/orderBill/input";
    }

    @RequestMapping("/view")
    @RequiredPermission("采购订单查看")
    public String view(Long id, Model model) {
        if (id != null) {
            OrderBill orderBill = orderBillService.get(id);
            model.addAttribute("orderBill", orderBill);
        }
        return "/orderBill/views";
    }

    @RequestMapping("delete")
    @RequiredPermission("采购订单删除")
    @ResponseBody
    public JSONResult delete(Long id) {
        if (id != null) {
            orderBillService.delete(id);
        }
        return new JSONResult();
    }

    @RequestMapping("/saveOrUpdate")
    @RequiredPermission("采购订单新增/更新")
    @ResponseBody
    public JSONResult saveOrUpdate(OrderBill orderBill) {
        orderBillService.saveOrUpdate(orderBill);
        return new JSONResult();
    }

    @RequestMapping("/audit")
    @RequiredPermission("采购订单审核")
    @ResponseBody
    public JSONResult audit(Long id) {
        if (id != null) {
            orderBillService.audit(id);
        }
        return new JSONResult();
    }


}
